﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Automaton.EntityTracking
{
    public abstract class BaseRepository
    {

        internal AutomatonEntities _context;
        internal bool _contextReused;

        public AutomatonEntities GetObjectContext()
        {
            if (!_contextReused)
            {
                return new AutomatonEntities();
            }
            return _context;
        }

        public void ReleaseObjectContextIfNotReused()
        {
            if (!_contextReused)
            {
                ReleaseObjectContext();
            }
        }

        public void ReleaseObjectContext()
        {
            if (_context != null)
            {
                _context.Dispose();
            }
            _contextReused = false;
        }
    }
}
